package com.xxxx.yoyo.web;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * Servlet implementation class LogoutServlet
 */
@WebServlet("/index/logout")
public class LogoutServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		HttpSession session = request.getSession();
		//删除session中的登录信息
		session.removeAttribute("user");
		//删除session中的购物车信息
		session.removeAttribute("order");
		
		//请求转发回到首页即/index/index servlet
		//request.getRequestDispatcher("/index/index").forward(request, response);
		
		//重定向
		response.sendRedirect("/YoyoShop/index/index");
	}

}
